<template>
  <div class="main-layout">
    <div class="main-content">
      <div class="mine-header">
        <div class="avatar-box">
          <img class="avatar" :src="getUserAvatar(user.photo, user.id)" alt="头像" />
        </div>
        <h2>个人设置</h2>
        <button class="edit-btn" @click="showEditTip = true">修改资料</button>
      </div>
      <div class="profile-info">
        <div class="info-item"><span class="label">用户ID：</span>{{ user.id || '未填写' }}</div>
        <div class="info-item">
          <span class="label">昵称：</span>{{ user.nickname || '未填写' }}
        </div>
        <div class="info-item"><span class="label">性别：</span>{{ user.sex || '未填写' }}</div>
        <div class="info-item">
          <span class="label">生日：</span>{{ user.birthday || '未填写' }}
        </div>
        <div class="info-item">
          <span class="label">签名：</span>{{ user.signature || '未填写' }}
        </div>
        <div class="info-item">
          <span class="label">城市：</span>{{ user.location || '未填写' }}
        </div>
        <div class="info-item"><span class="label">学校：</span>{{ user.school || '未填写' }}</div>
        <div class="info-item"><span class="label">爱好：</span>{{ user.hobby || '未填写' }}</div>
      </div>
      <div v-if="showEditTip" class="edit-tip-modal">
        <div class="edit-tip-content">
          <span>功能开发中，敬请期待！</span>
          <button class="close-btn" @click="showEditTip = false">关闭</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useAuthStore } from '@/stores/auth'
import api from '@/services/api'
import { getUserAvatar } from '@/utils/avatar'

const authStore = useAuthStore()
const user = computed(() => authStore.user || {})
const showEditTip = ref(false)

onMounted(async () => {
  if (!user.value || !user.value.nickname) {
    const res = await api.getUserInfo()
    if (res.data && res.data.code === 0) {
      authStore.user = res.data.data
    }
  }
})
</script>

<style scoped>
.main-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  background: var(--color-bg);
}
.main-content {
  width: 100%;
  max-width: 700px;
  margin: 2rem auto 0 auto;
  background: var(--color-input-bg);
  border-radius: 0.5rem;
  box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.04);
  padding: 2rem 2.5rem 2.5rem 2.5rem;
  min-height: 300px;
  position: relative;
}
.mine-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}
.avatar-box {
  display: flex;
  align-items: center;
  margin-right: 1.5rem;
}
.avatar {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 50%;
  object-fit: cover;
  border: 2.5px solid var(--color-primary);
  background: var(--color-surface, var(--color-input-bg));
}
.edit-btn {
  background-color: var(--color-primary);
  color: var(--color-button-text);
  border: none;
  border-radius: 0.4rem;
  padding: 0.6rem 1.3rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.08);
  transition: background 0.2s;
}
.edit-btn:hover {
  background-color: var(--color-primary-hover);
}
.profile-info {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  font-size: 1.08rem;
  color: var(--color-text);
  padding: 0 0.5rem;
  margin-top: 1.2rem;
}
.info-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-surface, var(--color-input-bg));
  border-radius: 0.3rem;
  padding: 0.5rem 0.8rem;
  margin-bottom: 0.2rem;
  box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.04);
}
.info-item .label {
  color: var(--color-text-label);
  font-weight: 500;
  min-width: 4.2em;
}
.edit-tip-modal {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.edit-tip-content {
  background: #fff;
  border-radius: 0.7rem;
  padding: 2rem 2.5rem;
  box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.13);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
}
.close-btn {
  background: var(--color-primary);
  color: var(--color-button-text);
  border: none;
  border-radius: 0.3rem;
  padding: 0.5rem 1.2rem;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 0.5rem;
}
.close-btn:hover {
  background: var(--color-primary-hover);
}
</style>
